{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "e815cc33",
   "metadata": {},
   "source": [
    "week4有序数据结构"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1747af5a",
   "metadata": {},
   "source": [
    "# 202209013 week4 python笔记"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "38162731",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(5)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "fe61b27f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 5)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,5)#终止的减去起始的是个数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d1a09aac",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,5):#for加range决定循环次数\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c7e10a89",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 10, 3)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,10,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "6490e418",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "4\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10,3):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "33678b78",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    ">1.数值\n",
    ">>1.int\n",
    ">>2.float\n",
    ">>3.complex\n",
    "\n",
    "\n",
    ">2.字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "6cf9ce68",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "##number 数值\n",
    "\n",
    "a=9 #int类型\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "7927d852",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11.5 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "b=11.5 #float类型#\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "2bdb0e25",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(5+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "#complex类型(复数虚数)\n",
    "c=5+3j\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f7bba477",
   "metadata": {},
   "source": [
    "# 字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8f5c64ee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name='alex'\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d5b6e2c0",
   "metadata": {},
   "source": [
    "# 2.2关于字符串的方法与函数\n",
    "1.\n",
    "2.\n",
    "3."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "1b4fc348",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院坐落于广州市从化温泉镇\n"
     ]
    }
   ],
   "source": [
    "#关于有序性\n",
    "title=\"广州南方学院坐落于广州市从化温泉镇\"\n",
    "print(title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "6344cc10",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0]#取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "536b947d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "17"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(title)#检查文本长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "5ae48f0d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0:6]#取一定范围的值，这种方法称为切片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "0e48aff5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'坐'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "82095496",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'市'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[-6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "988bb0af",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广\n",
      "州\n",
      "南\n",
      "方\n",
      "学\n",
      "院\n",
      "坐\n",
      "落\n",
      "于\n",
      "广\n",
      "州\n",
      "市\n",
      "从\n",
      "化\n",
      "温\n",
      "泉\n",
      "镇\n"
     ]
    }
   ],
   "source": [
    "##利用for循环 遍历文本信息\n",
    "for i in title:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "043056c8",
   "metadata": {},
   "outputs": [],
   "source": [
    "#思考 如何判断是否一段文本中存在广州 ##enumerate 枚举 即可以获取到内容也可以获取到索引值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "9e2d82a7",
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name '广州' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [24]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m name\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m广州\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28mprint\u001b[39m\u001b[38;5;241m=\u001b[39m(name,\u001b[38;5;28mtype\u001b[39m(\u001b[43m广州\u001b[49m))\n",
      "\u001b[1;31mNameError\u001b[0m: name '广州' is not defined"
     ]
    }
   ],
   "source": [
    "name='广州'\n",
    "print=(name,type(广州))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "5ab5a11c",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (2586583311.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [25]\u001b[1;36m\u001b[0m\n\u001b[1;33m    for i in range(广州)\u001b[0m\n\u001b[1;37m                      ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "for i in range(广州)\n",
    "print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "6e79c9aa",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (699819670.py, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  Input \u001b[1;32mIn [32]\u001b[1;36m\u001b[0m\n\u001b[1;33m    if j=\"广\"：\u001b[0m\n\u001b[1;37m        ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "for i,j in enumerate(title):\n",
    "    if j=\"广\"：\n",
    "    if title[i+1]==\"州\"：\n",
    "    print(\"广州这个词在这段文本中\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "2056799b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "##in 检查成员对象\n",
    "\"广州\"in title"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b7599e82",
   "metadata": {},
   "source": [
    "# 字符串的拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "988de20d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你好，Alex\n"
     ]
    }
   ],
   "source": [
    "print(\"你好，\"+\"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "6a4dc58a",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "unsupported operand type(s) for /: 'str' and 'str'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [34]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m#字符串不可以用来运算\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m3\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m2\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\n",
      "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'str' and 'str'"
     ]
    }
   ],
   "source": [
    "#字符串不可以用来运算\n",
    "\"3\"/\"2\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7738b774",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
